#include <string>
#include "scr_keyboard.h"

bool SCRKeyboard::mCurrentStateA[SCR_KEYSTATE_SIZE];
bool SCRKeyboard::mPreviousStateA[SCR_KEYSTATE_SIZE];

bool SCRKeyboard::IsPressed(const int& Key)
{
	const int MaskedKey = Key & SCR_KEYSTATE_MASK;
	
	return mCurrentStateA[MaskedKey];
}

bool SCRKeyboard::IsReleased(const int& Key)
{
	const int MaskedKey = Key & SCR_KEYSTATE_MASK;

	return !mCurrentStateA[MaskedKey] &&
		mPreviousStateA[MaskedKey];
}

bool SCRKeyboard::IsClicked(const int& Key)
{
	const int MaskedKey = Key & SCR_KEYSTATE_MASK;

	return mCurrentStateA[MaskedKey] &&
		!mPreviousStateA[MaskedKey];
}

void SCRKeyboard::InitializeState()
{
	std::memset(mCurrentStateA, 0, SCR_KEYSTATE_SIZE * sizeof(bool));
	std::memset(mPreviousStateA, 0, SCR_KEYSTATE_SIZE * sizeof(bool));
}

void SCRKeyboard::UpdateState()
{
	std::memcpy(mPreviousStateA, mCurrentStateA, SCR_KEYSTATE_SIZE * sizeof(bool));
}
